/*!
 * Copyright (C) 2020 - All Rights Reserved by
 * @author : ZhaoYanbo
 * @email  : zyb920@hotmail.com
 * @created: 2020-10-31
 * @version: 1.0.0.0
 *
 */

#include "widget.h"
#include "lyriceditwidget.h"
#include "le_scrollarea.h"
#include <QtWidgets>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(1100, 520);

    QPushButton *zoomIn_btn = new QPushButton("zoomIn", this);
    QPushButton *zoomOut_btn = new QPushButton("zoomOut", this);
    QPushButton *undo_btn = new QPushButton("undo", this);
    QPushButton *redo_btn = new QPushButton("redo", this);
    QPushButton *mode_btn = new QPushButton("switch mode", this);

    LE_ScrollArea *area = new LE_ScrollArea(this);

    zoomIn_btn->setFixedSize(100, 40);

    QHBoxLayout *hlay = new QHBoxLayout;
    hlay->setSpacing(12);
    hlay->setContentsMargins(0,0,0,0);
    hlay->addStretch(1);
    hlay->addWidget(undo_btn);
    hlay->addWidget(redo_btn);
    hlay->addWidget(mode_btn);
    hlay->addWidget(zoomIn_btn);
    hlay->addWidget(zoomOut_btn);
    hlay->addStretch(1);

    QVBoxLayout *vlay = new QVBoxLayout(this);
    vlay->setSpacing(8);
    vlay->setContentsMargins(0,0,0,8);
    vlay->addWidget(area, 1);
    vlay->addLayout(hlay);


    LyricEditWidget *lyricWidget = new LyricEditWidget(this);
    lyricWidget->setMinimumHeight(452);
    lyricWidget->resize(1100, 580);
    lyricWidget->setShowMode(FineShowMode::KaraokeShow);
    lyricWidget->setShowString("Create   Object  FK");
    //lyricWidget->setShowMode(FineShowMode::NormalShow);
    QVector<VPos> vPoints;
    vPoints.append(VPos(1.00));
    vPoints.append(VPos(1.40));
    vPoints.append(VPos(2.20));
    vPoints.append(VPos(3.40));
    vPoints.append(VPos(4.00));
    vPoints.append(VPos(4.60));
    vPoints.append(VPos(5.20));
    vPoints.append(VPos(5.50));
    vPoints.append(VPos(6.00));
    vPoints.append(VPos(6.30));
    vPoints.append(VPos(6.50));
    vPoints.append(VPos(6.80));
    vPoints.append(VPos(7.20));
    vPoints.append(VPos(7.60));
    vPoints.append(VPos(8.00));

    vPoints.first().canMove = true;
    vPoints.last().canMove = true;

    lyricWidget->openScaleMode(false);
    lyricWidget->loadFromValues(vPoints);

    area->setWidget(lyricWidget);

    connect(undo_btn, &QPushButton::clicked, lyricWidget, &LyricEditWidget::undo);
    connect(redo_btn, &QPushButton::clicked, lyricWidget, &LyricEditWidget::redo);
    connect(zoomIn_btn, &QPushButton::clicked,  lyricWidget, &LyricEditWidget::zoomIn);
    connect(zoomOut_btn, &QPushButton::clicked, lyricWidget, &LyricEditWidget::zoomOut);
    connect(mode_btn, &QPushButton::clicked, this, [lyricWidget]() {
        lyricWidget->setUpdatesEnabled(false);
        if(lyricWidget->showMode() != FineShowMode::NormalShow)
            lyricWidget->setShowMode(FineShowMode::NormalShow);
        else
            lyricWidget->setShowMode(FineShowMode::KaraokeShow);
        lyricWidget->setUpdatesEnabled(true);
    });
}

Widget::~Widget()
{
}

